package cn.yh.hospitalappointmentsystemdemo.common;

import lombok.Data;

import java.util.Map;

@Data
public class AjaxResult<T> {
    private String msg;
    private Integer code;
    private T data;

    public AjaxResult(String msg, Integer code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    /*
    * 成功返回结果
    * @param msg
    * @param code
    * @param data
    * return AjaxResult 返回结果*/
    public static AjaxResult success(String msg, Integer code, Object data) {
        return new AjaxResult(msg, code, data);
    }

    /*
    * 成功返回结果
    * @param data
    * return AjaxResult 返回结果*/
    public static AjaxResult success( Object data) {
        return new AjaxResult("操作成功", 200, data);
    }

    /*
    * 成功返回结果(空参数)
    * return AjaxResult 返回结果
    * */
    public static AjaxResult success() {
        return new AjaxResult("操作成功", 200, null);
    }

    /*
    * 成功返回结果
    * @param token
    * @param msg
    * return AjaxResult 返回结果
    * */
    public static AjaxResult success(String token, String msg) {
        return new AjaxResult(msg, 200, token);
    }

    public static AjaxResult success(Map<String, Object> resultMap, String msg){
        return new AjaxResult(msg, 200, resultMap);
    }

    /*
    * 失败返回结果
    * @param msg
    * return AjaxResult
    * */
    public static AjaxResult error(String msg) {
        return new AjaxResult(msg, 500, null);
}

    /*
     * 失败返回结果
     * @param data
     * @param msg
     * return AjaxResult
     * */
    public static AjaxResult error( Object data, String msg) {
        return new AjaxResult(msg, 500, data);
    }

    /*
    * 失败返回结果
    * @param data
    * @param msg
    * @param code
    * return AjaxResult
    * */
    public static AjaxResult error( Object data, String msg, Integer code) {
        return new AjaxResult(msg, code, data);
    }

    /*
    * 失败返回结果
    * return
    * */
    public static AjaxResult error() {
        return new AjaxResult("操作失败", 500, null);
    }

    /*
    * 失败返回结果
    * @param msg
    * @param code
    * return AjaxResult
    * */
    public static AjaxResult error(  String msg, Integer code) {
        return new AjaxResult(msg, code,null);
    }


    /*
    * 验证失败返回结果
    * @param msg
    * return AjaxResult
    * */
    public static AjaxResult verifyFail(String msg) {
        return new AjaxResult(msg, 401, null);
    }
}
